package ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements Ioperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int useSize = bookList.getUseSize();
        for (int i = 0; i < useSize; i++) {
            Book book = bookList.getBook(i);
//            先判断是否有这本书的存在
            if (book.getName().equals(name)) {
//                再判断书是否被借出
                if (!book.isBorrowed()) {
                    book.setBorrowed(true);
                    System.out.println("借阅成功");
                    return;
                }
                else {
                    System.out.println("这本书已经被借出");
                    return;
                }
            }
        }
//        遍历整个书架都没有要找的书
        System.out.println("没有你要借阅的书");
    }
}
